﻿Imports Microsoft.WindowsCE.Forms
Public Class frmTeam

    Dim LastTxtBox As TextBox
    Dim OldInputMod As InputMethod

    Private Sub frmTeam_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '记录以前的输入法，以便退出时改成它
        OldInputMod = InputPanel1.CurrentInputMethod
        LoadPrepare()
    End Sub
    Private Sub LoadPrepare()
        Dim mPrjOpt As LevelDatabase.CurrentOption
        'Dim mDB As New Db_CurrentOption
        mPrjOpt = MyShared.myDb.CurrentRead()
        If mPrjOpt.CurrentProject = String.Empty Then
            MsgBox("请设置当前工程！")
            Me.Close()
        Else
            lblPrj.Text = mPrjOpt.CurrentProject
            txtWkSv.Text = mPrjOpt.Surveyor
            txtWkRec.Text = mPrjOpt.Recordor
            txtWkExam.Text = mPrjOpt.Examor
        End If
        UpdateList()
    End Sub
    Private Sub UpdateList()
        'Dim mDb1 As New Db_Workers
        Try
            Dim sTmp As String = MyShared.myDb.WorkersRead()
            Dim sv() As String = sTmp.Split(vbCrLf)
            ListBox1.Items.Clear()
            For Each su As String In sv
                If su.Trim.Length > 0 Then
                    ListBox1.Items.Add(su.Trim)
                End If
            Next
        Catch ex As Exception

        End Try

    End Sub

    Private Sub frmTeam_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        '输入法改为以前的
        InputPanel1.CurrentInputMethod = OldInputMod
    End Sub

    Private Sub txtWkExam_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles txtWkExam.LostFocus, txtWkRec.LostFocus, txtWkSv.LostFocus
        LastTxtBox = CType(sender, TextBox)
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles ListBox1.SelectedIndexChanged
        LastTxtBox.Text = ListBox1.SelectedItem
    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mPrjOpt As New LevelDatabase.CurrentOption
        mPrjOpt.Recordor = txtWkRec.Text
        mPrjOpt.Examor = txtWkExam.Text
        mPrjOpt.Surveyor = txtWkSv.Text

        'Dim mDB As New Db_CurrentOption
        MyShared.myDb.CurrentRecord(mPrjOpt)
        Me.Close()

    End Sub


    Private Sub txtInstr_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _
    Handles txtWkExam.Validating, txtWkRec.Validating, txtWkSv.Validating
        Dim txt As TextBox
        txt = CType(sender, TextBox)

        Dim sTmp As String = CType(sender, TextBox).Text.Trim
        If sTmp.Length > 0 Then
            'Dim mDb As New Db_Workers
            MyShared.myDb.WorkwersRecordRow(sTmp)
            UpdateList()
        End If
    End Sub


    Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Dim mDb As New Db_Workers
        Dim sTmp As String = ListBox1.SelectedItem.ToString.Trim
        If sTmp.Length > 0 Then
            MyShared.myDb.WorkersDeleteRow(sTmp)
            LastTxtBox.Text = ""
            UpdateList()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button3.Text = "输中文" Then
            InputPanelSet.SetChinese(InputPanel1)
            Button3.Text = "关中文"
        Else
            InputPanelSet.SetNumeric(InputPanel1)
            Button3.Text = "输中文"
            InputPanel1.Enabled = False

        End If

    End Sub

End Class